package com.logistics.dictionary.entity.model;

import com.logistics.dictionary.entity.domain.Dictionary;
import com.logistics.utils.tool.DateUtils;
import com.logistics.utils.tool.StringUtils;
import lombok.Data;

import java.util.List;

@Data
public class DictionaryRow {

    private Integer id;
    private String name;
    private String code;
    private Integer parentId;
    private String externalCode;
    private String language;
    private List<DictionaryRow> children;
    private String creator;
    private String createTime;
    private String updater;
    private String updateTime;

    public DictionaryRow(){

    }

    public DictionaryRow(Dictionary dictionary){
        if(StringUtils.isNull(dictionary)){
            return;
        }
        this.id = dictionary.getId();
        this.name = dictionary.getName();
        this.code = dictionary.getCode();
        this.externalCode = dictionary.getExternalCode();
        this.parentId = dictionary.getParentId();
        this.language = dictionary.getLanguage();
        this.creator = dictionary.getCreator();
        this.createTime = DateUtils.dateToStringFormat(dictionary.getCreateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS);
        this.updater = dictionary.getUpdater();
        this.updateTime = DateUtils.dateToStringFormat(dictionary.getUpdateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS);
    }

    public static DictionaryRow build(Dictionary dictionary){
        return new DictionaryRow(dictionary);
    }
}
